(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/Script/DialogueComponent.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, '99023/TgktIsKt6GcMjXZQb', 'DialogueComponent', __filename);
// Script/DialogueComponent.ts

Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var DialogueComponent = (function (_super) {
    __extends(DialogueComponent, _super);
    function DialogueComponent() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    DialogueComponent.prototype.onLoad = function () {
        var _this = this;
        var url = "head/2";
        cc.loader.loadRes(url, cc.SpriteFrame, function (err, spriteFrame) {
            _this.showDialog({ list: [{ content: "h1" }, { content: "h2" }, { content: "h3" }, { content: "h4" }],
                buttons: [{ label: "功能1", click: function () { console.log("调用了功能1"); } }, { label: "功能2", click: function () { console.log("调用了功能2"); } }], head: spriteFrame, end: function () { } });
        });
        // init logic
    };
    DialogueComponent.prototype.showDialog = function (data) {
        this.buttonsLayout.node.active = false;
        this.data = data;
        this.head.spriteFrame = data.head;
        if (data.buttons != null) {
            //this.buttonsLayout.node.removeAllChildren();
            for (var i = 0; i < data.buttons.length; i++) {
                var btnInstance = cc.instantiate(this.buttonTemplate.node);
                btnInstance.active = true;
                var lblText = btnInstance.getComponentInChildren(cc.Label);
                lblText.string = data.buttons[i].label;
                btnInstance.on("click", data.buttons[i].click);
                this.buttonsLayout.node.addChild(btnInstance);
            }
        }
        this.nextContent();
    };
    DialogueComponent.prototype.nextContent = function () {
        var item = this.data.list.shift();
        if (this.data.list.length == 0) {
            this.buttonsLayout.node.active = true;
        }
        if (item != null) {
            this.content.string = item.content;
        }
        else {
            this.closeCurrent();
            if (this.data.end != null) {
                this.data.end();
            }
        }
    };
    DialogueComponent.prototype.accessTask = function () {
        console.log("接受任务");
        this.closeCurrent();
    };
    DialogueComponent.prototype.closeCurrent = function () {
        var s = "";
        this.node.active = false;
    };
    __decorate([
        property(cc.RichText)
    ], DialogueComponent.prototype, "content", void 0);
    __decorate([
        property(cc.Sprite)
    ], DialogueComponent.prototype, "head", void 0);
    __decorate([
        property(cc.Layout)
    ], DialogueComponent.prototype, "buttonsLayout", void 0);
    __decorate([
        property(cc.Button)
    ], DialogueComponent.prototype, "buttonTemplate", void 0);
    DialogueComponent = __decorate([
        ccclass
    ], DialogueComponent);
    return DialogueComponent;
}(cc.Component));
exports.default = DialogueComponent;

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=DialogueComponent.js.map
        